//
//  BDBaseViewController.m
//  BadBoy
//
//  Created by wen on 2017/3/10.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDBaseViewController.h"

@interface BDBaseViewController ()

@property (nonatomic, strong) UIView *errorView;

@property (nonatomic, copy) void(^errorViewTapBlock)();

@end

@implementation BDBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigation];
    self.startPage = @"1";
    self.pageSize = @"20";

    self.view.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
    if (@available(iOS 11, *)) {
        self.additionalSafeAreaInsets = UIEdgeInsetsMake(-20, 0, 0, 0);
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

- (void)setNavigation{
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:54/255.0 green:54/255.0 blue:54/255.0 alpha:1.0f]];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    self.extendedLayoutIncludesOpaqueBars=YES;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:17],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    //设置阴影
    self.navigationController.navigationBar.layer.shadowColor = [UIColor colorWithRed:54/255.0 green:54/255.0 blue:54/255.0 alpha:1.0f].CGColor;
    self.navigationController.navigationBar.layer.shadowOffset = CGSizeMake(0, 0);
    self.navigationController.navigationBar.layer.shadowOpacity = 1;
    self.navigationController.navigationBar.layer.shadowRadius = 5;
}

- (void)setTableiewFooterViewStateFor:(UITableView *)tableView datasourceCount:(NSInteger)count{
    if (self.isEnd == YES) {
        tableView.mj_footer = nil;
        if (count == 0) {
            UIView *bkView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, tableView.width)];
            bkView.backgroundColor = [UIColor clearColor];
            UIImageView *imgaeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth / 3.0, kBDScreenWidth / 3.0)];
            imgaeView.image = [UIImage imageNamed:@"wushuju"];
            imgaeView.center = CGPointMake(bkView.width / 2.0, bkView.height / 2.0);
            imgaeView.contentMode = UIViewContentModeScaleAspectFit;
            [bkView addSubview:imgaeView];
            
            UILabel *label = [[UILabel alloc] init];
            label.font = [UIFont systemFontOfSize:15];
            label.textColor = [UIColor colorWithHexString:@"#767676"];
            label.text = (ASLocalizedString(@"暂时没有数据"));
            [label sizeToFit];
            label.centerX = bkView.width / 2.0;
            label.top = imgaeView.bottom + 5;
            [bkView addSubview:label];
            tableView.tableFooterView = bkView;
            tableView.mj_header = nil;
        }else{
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.width, 40)];
            label.textColor = [UIColor colorWithHexString:@"#767676"];
            label.font = [UIFont systemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor clearColor];
            label.text = (ASLocalizedString(@"无更多内容"));
            tableView.tableFooterView = label;
        }
    }else{
        tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    }
}

- (void)setTableiewFooterViewStateFor:(UITableView *)tableView datasourceCount:(NSInteger)count guanzhuShangjia:(NSString *)shangjia{
    if (self.isEnd == YES) {
        tableView.mj_footer = nil;
        if (count == 0) {
            UIView *bkView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, tableView.width)];
            bkView.backgroundColor = [UIColor clearColor];
            UIImageView *imgaeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth / 3.0, kBDScreenWidth / 3.0)];
            imgaeView.image = [UIImage imageNamed:@"guanzhushangjia"];
            imgaeView.center = CGPointMake(bkView.width / 2.0, bkView.height / 2.0);
            imgaeView.contentMode = UIViewContentModeScaleAspectFit;
            [bkView addSubview:imgaeView];
            
            UILabel *label = [[UILabel alloc] init];
            label.font = [UIFont systemFontOfSize:15];
            label.textColor = [UIColor colorWithHexString:@"#767676"];
            label.text = (ASLocalizedString(@"暂无关注商家"));
            [label sizeToFit];
            label.centerX = bkView.width / 2.0;
            label.top = imgaeView.bottom + 5;
            [bkView addSubview:label];
            tableView.tableFooterView = bkView;
            tableView.mj_header = nil;
        }else{
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.width, 40)];
            label.textColor = [UIColor colorWithHexString:@"#767676"];
            label.font = [UIFont systemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor clearColor];
            label.text = (ASLocalizedString(@"无更多内容"));
            tableView.tableFooterView = label;
        }
    }else{
        tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    }
}

- (void)setReservationTableiewFooterViewStateFor:(UITableView *)tableView datasourceCount:(NSInteger)count{
    if (self.isEnd == YES) {
        tableView.mj_footer = nil;
        if (count == 0) {
            UIView *bkView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, tableView.width)];
            bkView.backgroundColor = [UIColor clearColor];
            UIImageView *imgaeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth / 3.0, kBDScreenWidth / 3.0)];
            imgaeView.image = [UIImage imageNamed:@"wudingdan"];
            imgaeView.center = CGPointMake(bkView.width / 2.0, bkView.height / 2.0);
            imgaeView.contentMode = UIViewContentModeScaleAspectFit;
            [bkView addSubview:imgaeView];
            
            UILabel *label = [[UILabel alloc] init];
            label.font = [UIFont systemFontOfSize:15];
            label.textColor = [UIColor colorWithHexString:@"#767676"];
            label.text = (ASLocalizedString(@"暂无订单"));
            [label sizeToFit];
            label.centerX = bkView.width / 2.0;
            label.top = imgaeView.bottom + 5;
            [bkView addSubview:label];
            tableView.tableFooterView = bkView;
            tableView.mj_header = nil;
        }else{
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.width, 40)];
            label.textColor = [UIColor colorWithHexString:@"#767676"];
            label.font = [UIFont systemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor clearColor];
            label.text = (ASLocalizedString(@"无更多内容"));
            tableView.tableFooterView = label;
        }
    }else{
        tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    }
}

- (void)showErrorViewWithTapBlock:(void (^)())block{
    self.errorView.hidden = NO;
    [self.view bringSubviewToFront:self.errorView];
    self.errorViewTapBlock = block;
}


- (UIView *)errorView{
    if (!_errorView) {
        self.errorView = [[UIView alloc] initWithFrame:self.view.frame];
        _errorView.backgroundColor = self.view.backgroundColor;
        
        UIImageView *iamgeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth / 2.0, kBDScreenHeight / 2.0)];
        iamgeView.center = _errorView.center;
        iamgeView.image = [UIImage imageNamed:@"wuwangluo"];
        iamgeView.contentMode = UIViewContentModeScaleAspectFit;
        iamgeView.userInteractionEnabled = YES;
        [_errorView addSubview:iamgeView];
        [self.view addSubview:_errorView];
        UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(errorViewTapAction)];
        [_errorView addGestureRecognizer:tapGR];
    }
    return _errorView;
}

- (void)errorViewTapAction{
    self.errorView.hidden = YES;
    if (self.errorViewTapBlock) {
        self.errorViewTapBlock();
    }
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
